const {NetUtils} = require("../utils/NetUtils");
const Services = require("ee-core/services");
const jsonUtils = require("ee-core/utils/json");

class ConfigContext {

    static globConfig = {
        amount: 0,
        bettingInterval: 0,
        frequency: [],
        imUrl: null,
        imHost: null,

        pbUserName: null,
        pbPassWord: null,
        pbUrl: null,
        pbHost: null,

    }

    static refreshGlobConfig() {
        Services.get("sureBetSqliteDb").getDbValueByKey("glob_key").then(res=>{
            if (!res) {
                throw new ReferenceError("请配置系统参数");
            }
            let value = jsonUtils.strictParse(res);
            let imHost = NetUtils.getHost(value.imUrl);
            let pbHost = NetUtils.getHost(value.pbUrl);

            ConfigContext.globConfig = value;
            ConfigContext.globConfig.imHost = imHost;
            ConfigContext.globConfig.pbHost = pbHost;
        })
    }

}

module.exports = {ConfigContext};